const multer = require('multer')
const path = require('path')

const storage = multer.diskStorage({
  destination(req, file, callback) {
    callback(null, path.join(__dirname, '../public/uploads'))
  },
  filename(req, file, callback) {
    const fileFormat = file.originalname.split('.')
    callback(null, `${fileFormat[0]}-${Date.now()}.${fileFormat[fileFormat.length - 1]}`)
  }
})

const upload = multer({
  storage
})

module.exports = upload
